﻿@if (false) {<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.7.min.js" type="text/javascript" />}
@{string list = "list3", pager = "pager3", entity = "User";}
<table id="@list" class="scroll" cellpadding="0" cellspacing="0">
</table>
<div id="@pager" class="scroll" style="text-align: center;">
</div>
<script type="text/javascript">
    jQuery(function () {
        $("#@list").jqGrid({
            url: "/@entity/index/",
            colNames: ["账户", "姓名", "角色"],
            colModel: [
            $.jgridx.strCol("UserName"),
            $.jgridx.strCol("Name"),
            { name: 'Role', index: 'Role', width: 80, editable: true, edittype: "select",
                editoptions: { dataUrl: "/User/GetRoles", buildSelect: function (data) {
                    var json = jQuery.parseJSON(data)
                    var v = json.value
                    var st = "<select>";
                    for (var i in v) {
                        st += "<option value='" + v[i].key + "'>" + v[i].value + "</option>";
                    }
                    st += "</select>";
                    return st;
                }
                },

                formoptions: { elmsuffix: '<span style="color:red">*<span>' },
                stype: "select",
                searchrules: { required: true },
                searchoptions:
                    { sopt: ["eq"],
                        dataUrl: "/User/GetRoles", buildSelect: function (data) {
                            var json = jQuery.parseJSON(data)
                            var v = json.value
                            var st = "<select><option>请选择</option>";
                            for (var i in v) {
                                st += "<option value='" + v[i].key + "'"
                                //if(i==0){st += "selected='selected'";}
                                st += ">" + v[i].value + "</option>";
                            }
                            st += "</select>";
                            return st;
                        }
                    }
                }
            ],

            pager: $('#@pager'),
//            sortname: "@(entity)Id",
//            sortorder: "desc",
            cmTemplate: { sortable: false },
            loadComplete: function (data) {

                if (!data.success)
                    $(this).jqGrid("clearGridData", true);
            }
        });
        $("#@list").jqGrid('navGrid', '#@pager',
        {
            edit: true,
            add: true,
            search: false,
            del: true,
            refresh: true
        },
        {
            url: "/@entity/edit/"
        },
        {
            bottominfo: '用户密码默认为000000<br /><span style="color:red">*<span>表示必填',
            url: "/@entity/add/"
        },
        {
            url: "/@entity/delete/"
        }, {}, {}).jqGrid('navButtonAdd', "@pager", { caption: "",
            buttonicon: "ui-icon ui-icon-transfer-e-w",
            onClickButton: function () {
                var rowid = $("#@list").jqGrid('getGridParam', 'selrow');
                if (rowid == null) {
                    alert("请选择一条记录");
                    return false;
                }
                var gr = $("#@list").jqGrid('getRowData', rowid);
                $.get("/user/resetpassword?username=" + gr.UserName, function (data) {
                    if (data.success) {
                        Alert("提示", "重置密码成功！");
                    } else {
                        Alert("错误", data.message);
                    }

                });
            },
            position: "last",
            title: "重置密码为000000"
        });

    });
</script>
